home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfpat6.zip / MENUTO.PRG < prev    next >
Text File  |  1993-01-12  |  21KB  |  605 lines

  1. /*
  2.  * File......: MENUTO.PRG
  3.  * Author....: Ted Means
  4.  * Date......: $Date:   12 Jan 1993 08:57:08  $
  5.  * Revision..: $Revision:   1.6  $
  6.  * Log file..: $Logfile:   C:/nanfor/src/menuto.prv  $
  7.  * 
  8.  * This is an original work by Ted Means and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   C:/nanfor/src/menuto.prv  $
  15.  * 
  16.  *    Rev 1.6   12 Jan 1993 08:57:08   GLENN
  17.  * Ted fixed a bug in which an array bounds error could occur if you
  18.  * used nested submenus.
  19.  * 
  20.  *    Rev 1.5   16 Oct 1992 00:20:28   GLENN
  21.  * Cleaned up documentation header.
  22.  * 
  23.  *    Rev 1.4   16 Oct 1992 00:08:44   GLENN
  24.  * Just making sure we had Ted's latest revision.
  25.  * 
  26.  *    Rev 1.3   13 Oct 1992 20:45:46   GLENN
  27.  * Complete rewrite by Ted Means, dumping assembler version for a
  28.  * Clipper version.
  29.  * 
  30.  *    Rev 1.2   15 Aug 1991 23:03:54   GLENN
  31.  * Forest Belt proofread/edited/cleaned up doc
  32.  * 
  33.  *    Rev 1.1   14 Jun 1991 19:52:16   GLENN
  34.  * Minor edit to file header
  35.  * 
  36.  *    Rev 1.0   01 Apr 1991 01:01:42   GLENN
  37.  * Nanforum Toolkit
  38.  *
  39.  */
  40.  
  41. /*  $DOC$
  42.  *  $FUNCNAME$
  43.  *     FT_Prompt()
  44.  *  $CATEGORY$
  45.  *     Menus/Prompts
  46.  *  $ONELINER$
  47.  *     Define a menu item for use with FT_MenuTo()
  48.  *  $SYNTAX$
  49.  *     #include "FTMENUTO.CH"
  50.  *
  51.  *     @ <nRow>, <nCol> PROMPT <cPrompt>                     ;
  52.  *                      [COLOR <cColor>]                     ;
  53.  *                      [MESSAGE <cMessage>]                 ;
  54.  *                      [MSGROW <nMsgRow>]                   ;
  55.  *                      [MSGCOL <nMsgCol>]                   ;
  56.  *                      [MSGCOLOR <cMsgColor>]               ;
  57.  *                      [TRIGGER <nTrigger>]                 ;
  58.  *                      [TRIGGERCOLOR <cTriggerColor>]       ;
  59.  *                      [HOME <nHome>]                       ;
  60.  *                      [END <nEnd>]                         ;
  61.  *                      [UP <nUp>]                           ;
  62.  *                      [DOWN <nDown>]                       ;
  63.  *                      [LEFT <nLeft>]                       ;
  64.  *                      [RIGHT <nRight>]                     ;
  65.  *                      [EXECUTE <bExec>]                    ;
  66.  *
  67.  *  $ARGUMENTS$
  68.  *     <nRow> is the row at which the prompt is to appear.
  69.  *
  70.  *     <nCol> is the column at which the prompt will appear.
  71.  *
  72.  *     <cPrompt> is the menu item string.
  73.  *
  74.  *     <cColor> is optional and is the color attribute of the prompt.  Note
  75.  *     that two colors are required; one for the standard setting and one
  76.  *     for the enhanced setting (i.e. the light bar color).  See the example
  77.  *     below if this isn't clear.  If <cColor> is not specified then the
  78.  *     current SetColor() value is used by default.
  79.  *
  80.  *     <cMessage> is optional and is the message associated with the
  81.  *     prompt. If not specified, then no message will be displayed.
  82.  *
  83.  *     <nMsgRow> is optional and is the row at which the message, if any,
  84.  *     will appear.  If not specified, the default is the current setting
  85.  *     of the SET MESSAGE TO command.
  86.  *
  87.  *     <nMsgCol> is optional and is the column at which the message, if
  88.  *     any, will appear.  If not specified, the default is either zero or
  89.  *     centered, depending on the current setting of the CENTER option of
  90.  *     the SET MESSAGE TO command.
  91.  *
  92.  *     <cMsgColor> is optional and is the color attribute of the message.
  93.  *     If not specified, the default is the same as the prompt color.
  94.  *
  95.  *     <nTrigger> is optional and is the position within the prompt string
  96.  *     where the trigger character is located.  If not specified, the
  97.  *     default is one.
  98.  *
  99.  *     <cTriggerColor> is optional and is the color attribute of the trigger
  100.  *     character.  Note that two colors are required; one for the standard
  101.  *     setting and one for the enhanced setting (i.e. the light bar color).
  102.  *     See the example below if this isn't clear.  If <cTriggerColor> is not
  103.  *     specified then the default is the same color as the rest of the
  104.  *     prompt.
  105.  *
  106.  *     <nHome> is optional and specifies which prompt becomes active
  107.  *     when the home key is pressed.  If not specified, the default is
  108.  *     the first prompt.
  109.  *
  110.  *     <nEnd> is optional and specifies which prompt becomes active
  111.  *     when the end key is pressed.  If not specified, the default is
  112.  *     the last prompt.
  113.  *
  114.  *     <nUp> is optional and specifies which prompt becomes active
  115.  *     when the up arrow key is pressed.  If not specified, the
  116.  *     default is the previous prompt.  The current setting of SET
  117.  *     WRAP TO is obeyed.
  118.  *
  119.  *     <nDown> is optional and specifies which prompt becomes
  120.  *     active when the down arrow key is pressed.  If not
  121.  *     specified, the default is the next prompt.  The current
  122.  *     setting of SET WRAP TO is obeyed.
  123.  *
  124.  *     <nRight> is optional and specifies which prompt becomes
  125.  *     active when the right arrow key is pressed.  If not
  126.  *     specified, the default is the next prompt.  The current
  127.  *     setting of SET WRAP TO is obeyed.
  128.  *
  129.  *     <nLeft> is optional and specifies which prompt becomes
  130.  *     active when the left arrow is pressed.  If not specified,
  131.  *     the default is the previous prompt.  The current setting of
  132.  *     SET WRAP TO is obeyed.
  133.  *
  134.  *     <bExec> is optional and is a code block to evaluate whenever
  135.  *     the menu item to which it belongs is selected.
  136.  *  $DESCRIPTION$
  137.  *     Clipper's @...PROMPT and MENU TO commands are fine as far as
  138.  *     they go.  But many times you need more flexibility.  As
  139.  *     you'll no doubt notice if you read the argument list, this
  140.  *     function is almost completely flexible. You can adjust
  141.  *     locations and colors for every part of the prompt and its
  142.  *     associated message.  In addition, since you can control the
  143.  *     effect of the arrow keys, you can allow both horizontal and
  144.  *     vertical movement, or even disable certain arrow keys if you
  145.  *     so desire.  Support for nested menus is also available, since
  146.  *     the prompts are stored in stack-based static arrays.
  147.  *
  148.  *     Note that this command can also be called using function-style
  149.  *     syntax.  See the entry for FT_PROMPT() for further details.
  150.  *
  151.  *     This enhanced version of @...PROMPT requires the inclusion of
  152.  *     the header file FTMENUTO.CH in any source file that uses it.
  153.  *     It is may be used in place of the standard Clipper @...PROMPT
  154.  *     command.  However, in the interests of functionality it is NOT
  155.  *     100% compatible.  No whining!  If compatibility is such a big
  156.  *     deal then use the standard Clipper commands.
  157.  *
  158.  *  $EXAMPLES$
  159.  *    #include "FTMENUTO.CH"
  160.  *
  161.  *    // Simple prompt
  162.  *    @ 1, 1 PROMPT "Menu choice #1"
  163.  *
  164.  *    // Prompt with color
  165.  *    @ 3, 1 PROMPT "Menu choice #2" COLOR "W+/R,W+/B"
  166.  *
  167.  *    // Prompt with a message
  168.  *    @ 5, 1 PROMPT "Menu choice #3" MESSAGE "Go to lunch"
  169.  *
  170.  *    // Prompt with pinpoint message control
  171.  *    @ 7, 1 PROMPT "Menu choice #4" MESSAGE "Drop Dead" ;
  172.  *                   MSGROW 22 MSGCOL 4 MSGCOLOR "GR+/N"
  173.  *
  174.  *    // Prompt with a trigger character ("#" character)
  175.  *    @11, 1 PROMPT "Menu choice #6" TRIGGER 13
  176.  *
  177.  *    // Prompt with trigger character color control
  178.  *    @13, 1 PROMPT "Menu Choice #7" TRIGGER 13 TRIGGERCOLOR "R+/BG,G+/N"
  179.  *
  180.  *    // Prompt with right and left arrow keys disabled
  181.  *    @15, 1 PROMPT "Menu Choice #8" RIGHT 8 LEFT 8
  182.  *  $INCLUDE$
  183.  *     FTMENUTO.CH
  184.  *  $SEEALSO$
  185.  *   
  186.  *  $END$
  187.  */
  188.  
  189. #include "SETCURS.CH"
  190. #include "INKEY.CH"
  191.  
  192. #xcommand if <true> then <action> => ;
  193.           if <true> ; <action> ; end
  194.  
  195. #xtranslate display( <row>, <col>, <stuff>, <color> ) => ;
  196.             setpos( <row>, <col> ) ; dispout( <stuff>, <color> )
  197.  
  198. #xtranslate EnhColor( <colorspec> ) => ;
  199.             substr( <colorspec>, at( ",", <colorspec> ) + 1 )
  200.  
  201. #xtranslate isOkay( <exp> ) => ;
  202.             ( <exp> \> 0 .and. <exp> \<= nCount )
  203.  
  204. #xtranslate isBetween( <val>, <lower>, <upp